package com.toggery.POS.service;

import com.toggery.POS.entity.Inventory;
import com.toggery.POS.entity.InventoryRecord;
import com.toggery.POS.dao.InventoryMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class InventoryService {
    @Autowired
    InventoryMapper mapper ;

    public List<InventoryRecord> findAllRecord(){
        return  mapper.countByclothing();
    }
    public List<Inventory> findAll(){
        return  mapper.findAll();
    }
    public List<Inventory> findAllWithClothing(int clothingid){
        return  mapper.findAllWithClothing(clothingid);
    }
    public boolean save(Inventory inventory){
        if(mapper.selectByPrimaryKey(inventory.getId())==null){
            mapper.insert(inventory);
            return true;
        }else {
            return false;
        }

    }
    public boolean updateInventory(Inventory inventory){
        if(mapper.updateByPrimaryKey(inventory)>0){
            return true;
        }else {
            return false;
        }
    }
    public boolean deleteByid(int id){
        if(mapper.deleteByPrimaryKey(id)>0){
            return true;
        }else {
            return false;
        }
    }
    public Inventory findById(int id){
        return mapper.selectByPrimaryKey(id);
    }


}
